/**
 * 
 */
package com.rostami.tutorial.spring.lifeCycle;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Alireza
 *
 */
public class LifeCycleAnnotation {
	
	public void printMessage(){
		System.out.println("It is greeting from the body!");
	}
	
	@PostConstruct
	public void initAnnotation(){
		System.out.println("initAnnotation");
	}
	
	@PreDestroy
	public void destroyAnnotation(){
		System.out.println("destroyAnnotation");
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext("SpringConfig.xml");
		LifeCycleAnnotation obj = (LifeCycleAnnotation)context.getBean("lifeCycleAnnotationBean");
		obj.printMessage();
		((AbstractApplicationContext)context).registerShutdownHook();

	}

}
